/******************************************************************************
*
*  MP3Play Widget -- Button
*  Created by Patrick Neeley <patrick@neeley.org>
*             http://www.neeley.org/
*  Created on 2007.08.02
*  Updated on 2007.08.03
*
*  Description:

   A button.  Can either have text, or a library-loaded image.  Can be made 
   skinnable, some day.

******************************************************************************/

import flash.MovieClip;


class Button extends Component
{
  var g_mcImage : MovieClip;

  public function new (root, data:String, textual:Bool, ?x, ?y, ?w, ?h)
  {
    super(root, true);

    this.move(x,y,w,h);
    this.setVisible(visible);
    this.setColor(0xDFDFDF);

    g_mcImage = null;

    this.setDisplay(data, textual);

    this.mc.onPress = this.onPressHandler;
    this.mc.onRollOver = this.onRollOverHandler;
    this.mc.onRollOut = this.onRollOutHandler;
  }
  // end function new


  public function setDisplay (data:String, textual:Bool)
  {
      // remove the existing image, if it exists
    if (g_mcImage != null) {
      g_mcImage.removeMovieClip();
      g_mcImage.destroy();
    }

      // set the text
    if (textual) {
      tf.textColor = 0x000000;
      tf.text = data;
    }
      // or the image
    else {
      tf.text = "";
      var d = this.mc.getNextHighestDepth();
      g_mcImage = this.mc.attachMovie(data, "image"+d, d);
      g_mcImage.moveTo(0,0);
      g_mcImage._width = this._width;
      g_mcImage._height = this._height;
    }
  }


  public function onPressHandler () { this.onPress(); }
  public function onRollOverHandler () { this.onRollOver(); }
  public function onRollOutHandler () { this.onRollOut(); }
  public function onPress () {}
  public function onRollOver () {}
  public function onRollOut () {}


  public function destroy ()
  {
    super.destroy();
  }
  // end function destroy


}
// end class SongEntry
